using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Net;
using System.IO;
using System.Text.RegularExpressions;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;

using Winista.Text.HtmlParser;
using Winista.Text.HtmlParser.Lex;
using Winista.Text.HtmlParser.Visitors;


//using Winista.Text.HtmlParser.Tags;
//using Winista.Text.HtmlParser.Util;
//using Winista.Text.HtmlParser.Extractors;
//using Winista.Text.HtmlParser.Data;
//using Winista.Text.HtmlParser.Filters;
//using Winista.Text.HtmlParser.Http;
//using Winista.Text.HtmlParser.Support;


/// <summary>
/// Summary description for RequestParser
/// </summary>
public class ResponseParser
{
    private string url, configPath;


    public ResponseParser(string url, string appConfigPath)
    {
        this.url = url;
        this.configPath = configPath;
        Parser.SetConfigLocation(appConfigPath);
    }

    public string Url
    {
        get
        {
            return this.url;
        }
    }

    public ArrayList Links()
    {
        ArrayList links = new ArrayList();
        try
        {       
            Winista.Text.HtmlParser.Extractors.LinkExtractor linkExtractor = new Winista.Text.HtmlParser.Extractors.LinkExtractor(this.url);
            Winista.Text.HtmlParser.Data.LinkStatus st = linkExtractor.ExtractLinks();

            foreach (Winista.Text.HtmlParser.Data.LinkData ld in linkExtractor.Links)
            {
                links.Add(ld.Url);
            }

        }
        catch (Exception e)
        {
            Console.WriteLine(e.StackTrace);
        }
        return links;

    }


    public string getText()
    {
        Parser parser = new Parser();
        Lexer lexer = new Lexer();
   
        Winista.Text.HtmlParser.Lex.Page page = new Winista.Text.HtmlParser.Lex.Page();

        lexer.Page = page;
        parser.Lexer = lexer;

        TextExtractingVisitor visitor = new TextExtractingVisitor();

        try
        {

            Winista.Text.HtmlParser.Extractors.StringExtractor extractor = new Winista.Text.HtmlParser.Extractors.StringExtractor(this.url);

            parser.VisitAllNodesWith(extractor);

            string str = extractor.GetStrings();

            return extractor.GetStrings();
        }
        catch (Exception e)
        {
            Console.WriteLine(e.StackTrace);
        }
        return string.Empty;
    }
}
